package website.seamonster.ethegg.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import website.seamonster.ethegg.dataobject.Msg;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

/**
 * Created by 罗海量
 * 2018-07-17 19:01
 */
public interface MsgRepository extends JpaRepository<Msg, String> {
    Page<Msg> findAllByUserIdOrderByCreateTimeDesc(String userId, Pageable pageable);

    List<Msg> findAllByUserIdAndMsgTypeAndCreateTime(String userId, Integer msgType, Timestamp createTime);

    @Query("select max(m.blockNum) from Msg m")
    Long getMaxBlockNum();

    Msg getFirstByUserIdAndMsgTypeOrderByBlockNumAsc(String userId, Integer msgTypeBuySuccess);

    @Query("select sum(m.income) from Msg m where m.userId=?1 and m.msgType=?2")
    BigDecimal sumIncome(String accountAddress, Integer msgTypeCode);

}
